/*     */ package com.zimbra.qa.unittest;
/*     */ 
/*     */ import com.zimbra.client.ZMailbox;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.DistributionList;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.mailbox.ACL;
/*     */ import com.zimbra.cs.mailbox.Folder;
/*     */ import com.zimbra.cs.mailbox.Folder.FolderOptions;
/*     */ import com.zimbra.cs.mailbox.MailItem.Type;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.mailbox.MailboxManager;
/*     */ import com.zimbra.soap.account.message.GetShareInfoRequest;
/*     */ import com.zimbra.soap.account.message.GetShareInfoResponse;
/*     */ import com.zimbra.soap.type.ShareInfo;
/*     */ import java.util.Collections;
/*     */ import java.util.List;
/*     */ import junit.framework.TestCase;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TestAclPush
/*     */   extends TestCase
/*     */ {
/*     */   private static final String NAME_PREFIX = "TestAclPush";
/*     */   private static final String USER1_NAME = "user1";
/*     */   private static final String USER2_NAME = "user2";
/*     */   private Account acct1;
/*     */   private String[] origSharedItem;
/*     */   private DistributionList dl;
/*     */   
/*     */   protected void setUp()
/*     */     throws Exception
/*     */   {
/*  50 */     this.acct1 = Provisioning.getInstance().getAccountByName(TestUtil.getAddress("user1"));
/*  51 */     this.origSharedItem = this.acct1.getSharedItem();
/*  52 */     this.acct1.unsetSharedItem();
/*  53 */     this.dl = Provisioning.getInstance().createDistributionList(TestUtil.getAddress("TestAclPush-dl"), Collections.emptyMap());
/*     */     
/*  55 */     this.dl.addMembers(new String[] { TestUtil.getAddress("user2") });
/*     */   }
/*     */   
/*     */   public void testAclPushAndDiscovery() throws Exception
/*     */   {
/*  60 */     Mailbox mbox1 = MailboxManager.getInstance().getMailboxByAccount(this.acct1);
/*  61 */     Folder.FolderOptions fopt = new Folder.FolderOptions().setDefaultView(MailItem.Type.DOCUMENT);
/*  62 */     Folder folder = mbox1.createFolder(null, "/TestAclPush-folder1", fopt);
/*     */     
/*     */ 
/*  65 */     Account acct2 = Provisioning.getInstance().getAccountByName(TestUtil.getAddress("user2"));
/*  66 */     mbox1.grantAccess(null, folder.getId(), acct2.getId(), (byte)1, ACL.stringToRights("r"), null);
/*     */     
/*  68 */     Thread.sleep(100L);
/*     */     
/*     */ 
/*  71 */     ZMailbox zMailbox2 = TestUtil.getZMailbox("user2");
/*  72 */     GetShareInfoRequest req = new GetShareInfoRequest();
/*  73 */     GetShareInfoResponse resp = (GetShareInfoResponse)zMailbox2.invokeJaxb(req);
/*  74 */     List<ShareInfo> shares = resp.getShares();
/*  75 */     ShareInfo share = getShare(shares, "/TestAclPush-folder1");
/*  76 */     assertNotNull(share);
/*  77 */     assertEquals(acct2.getId(), share.getGranteeId());
/*  78 */     assertEquals(ACL.typeToString((byte)1), share.getGranteeType());
/*  79 */     assertEquals(folder.getPath(), share.getFolderPath());
/*  80 */     assertEquals(folder.getId(), share.getFolderId());
/*  81 */     assertEquals(folder.getUuid(), share.getFolderUuid());
/*  82 */     assertEquals(folder.getDefaultView().toString(), share.getDefaultView());
/*  83 */     assertEquals("r", share.getRights());
/*  84 */     assertEquals(this.acct1.getId(), share.getOwnerId());
/*     */     
/*     */ 
/*  87 */     mbox1.rename(null, folder.getId(), MailItem.Type.FOLDER, "/TestAclPush-folder2");
/*  88 */     Thread.sleep(100L);
/*  89 */     resp = (GetShareInfoResponse)zMailbox2.invokeJaxb(req);
/*  90 */     shares = resp.getShares();
/*  91 */     assertNotNull(getShare(shares, "/TestAclPush-folder2"));
/*     */     
/*     */ 
/*  94 */     Folder dlFolder = mbox1.createFolder(null, "/TestAclPush-dl", fopt);
/*  95 */     mbox1.grantAccess(null, dlFolder.getId(), this.dl.getId(), (byte)2, ACL.stringToRights("rwi"), null);
/*  96 */     Thread.sleep(100L);
/*  97 */     resp = (GetShareInfoResponse)zMailbox2.invokeJaxb(req);
/*  98 */     shares = resp.getShares();
/*  99 */     ShareInfo dlShare = getShare(shares, "/TestAclPush-dl");
/* 100 */     assertNotNull(dlShare);
/* 101 */     assertEquals(this.dl.getId(), dlShare.getGranteeId());
/* 102 */     assertEquals(dlFolder.getPath(), dlShare.getFolderPath());
/* 103 */     assertEquals(dlFolder.getDefaultView().toString(), dlShare.getDefaultView());
/* 104 */     assertEquals("rwi", dlShare.getRights());
/* 105 */     assertEquals(this.acct1.getId(), dlShare.getOwnerId());
/*     */     
/*     */ 
/* 108 */     Folder pubFolder = mbox1.createFolder(null, "/TestAclPush-public", fopt);
/* 109 */     mbox1.grantAccess(null, pubFolder.getId(), null, (byte)6, ACL.stringToRights("rw"), null);
/* 110 */     Thread.sleep(100L);
/* 111 */     resp = (GetShareInfoResponse)zMailbox2.invokeJaxb(req);
/* 112 */     shares = resp.getShares();
/* 113 */     ShareInfo pubShare = getShare(shares, "/TestAclPush-public");
/* 114 */     assertNotNull(pubShare);
/* 115 */     assertEquals(pubFolder.getPath(), pubShare.getFolderPath());
/* 116 */     assertEquals(pubFolder.getDefaultView().toString(), pubShare.getDefaultView());
/* 117 */     assertEquals("rw", pubShare.getRights());
/* 118 */     assertEquals(this.acct1.getId(), pubShare.getOwnerId());
/*     */     
/*     */ 
/* 121 */     mbox1.revokeAccess(null, folder.getId(), acct2.getId());
/* 122 */     Thread.sleep(100L);
/* 123 */     resp = (GetShareInfoResponse)zMailbox2.invokeJaxb(req);
/* 124 */     shares = resp.getShares();
/* 125 */     assertNull(getShare(shares, "/TestAclPush-folder2"));
/* 126 */     assertNotNull(getShare(shares, "/TestAclPush-dl"));
/* 127 */     assertNotNull(getShare(shares, "/TestAclPush-public"));
/*     */     
/*     */ 
/* 130 */     mbox1.delete(null, dlFolder.getId(), MailItem.Type.FOLDER);
/* 131 */     mbox1.delete(null, pubFolder.getId(), MailItem.Type.FOLDER);
/* 132 */     Thread.sleep(100L);
/* 133 */     resp = (GetShareInfoResponse)zMailbox2.invokeJaxb(req);
/* 134 */     shares = resp.getShares();
/* 135 */     assertNull(getShare(shares, "/TestAclPush-dl"));
/* 136 */     assertNull(getShare(shares, "/TestAclPush-public"));
/*     */   }
/*     */   
/*     */   private static ShareInfo getShare(List<ShareInfo> shares, String folderPath) {
/* 140 */     for (ShareInfo si : shares) {
/* 141 */       if (folderPath.equals(si.getFolderPath())) {
/* 142 */         return si;
/*     */       }
/*     */     }
/* 145 */     return null;
/*     */   }
/*     */   
/*     */   protected void tearDown() throws Exception
/*     */   {
/* 150 */     TestUtil.deleteTestData("user1", "TestAclPush");
/* 151 */     this.acct1.setSharedItem(this.origSharedItem);
/* 152 */     Provisioning.getInstance().deleteDistributionList(this.dl.getId());
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/TestAclPush.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */